<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录页</title>
    <link rel="stylesheet" href="plugins/layui/css/layui.css">
    <link rel="stylesheet" href="css/style.css">
</head>
<body class="login-body">
<div class="login-main">
    <header class="layui-elip">登录</header>
    <form class="layui-form">
        <div class="layui-input-inline">
            <input type="text" name="account" id="account" required lay-verify="required" placeholder="用户名" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline">
            <input type="password" name="password" required lay-verify="required" placeholder="密码" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline login-btn">
            <button lay-submit lay-filter="login" class="layui-btn">登录</button>
        </div>
        <hr/>
    </form>
</div>


<script src="plugins/layui/layui.js"></script>
<script src="libs/jquery.min.js"></script>
<script type="text/javascript">
    $(function() {
        //判断是否登录
        $.ajax({
            url:'/sys/getLoginInfo',
            dataType:'text',
            success:function (data) {
                data = eval('(' + data + ')');
                if (data.code == '200'){
                    location.href = "./indexNew.html";
                }
            }
        })
    })

    layui.use(['form','layer','jquery'], function () {
        // 操作对象
        var form = layui.form;
        var $ = layui.jquery;
        form.on('submit(login)',function (data) {
            // console.log(data.field);
            $.ajax({
                url:'/sys/login',
                data:data.field,
                dataType:'text',
                type:'post',
                success:function (data) {
                    data = eval('(' + data + ')');
                    if (data.code == '200'){
                        console.log(data);
                        location.href = "./indexNew.html";
                    }else{
                        layer.msg('登录名或密码错误');
                    }
                }
            })
            return false;
        })
    });
</script>
</body>
</html>